用 make menuconfig 图形化配置 uboot

您所在的位置:网站首页 uboot 编译 用 make menuconfig 图形化配置 uboot

用 make menuconfig 图形化配置 uboot

2023-04-07 14:17| 来源: 网络整理| 查看: 265

uboot图形化配置及其原理

uboot可以通过 mx6ull_xxx_defconfig和 mx6ull_xxx_emmc.h文件来配置;另外还有一种配置uboot的方法,就是图形化配置

1. U-Boot图形化配置1.1 图形化配置简介

uboot或Linux内核可以通过输入“make menuconfig”来打开图形化配置界面,menuconfig是一套图形化的配置工具,需要ncurses库支持。ncurses库提供零一系列的API函数供调用者生成基于文本的图形界面,因此需要先在Ubuntu中安装ncurses库

sudo apt-get install build-essential sudo apt-get install libncurses5-dev

menuconfig重点会用到两个文件:“.config”和“Kconfig”,.config文件保存着uboot的配置项,使用menuconfig配置完uboot后该文件会被更新;Kconfig文件是图形界面的描述文件,即描述界面应该有什么内容,很多目录下都会有Kconfig文件

1.2 U-Boot图形化配置体验

在打开图形化配置界面前,需要先对uboot进行一次默认配置。之后使用“make menuconfig”命令打开图形化界面,打开后的界面如下示:

主界面上方的英文就是简单的操作说明,操作方法如下:

-- 通过键盘上的向上和向下按键选择要配置的菜单,“Enter"按键进入 -- 选中后按下"Y"键就会将相应的代码编译进uboot中,菜单前面变为 -- 选中后按下"N"键就会取消编译相应的代码 -- 选中后按下"M"键就会将相应的代码编译为模块,菜单前面变为< M > -- 按两下"Esc"键退出,也就是返回到上一级 -- 按下"?"键查看选中菜单的帮助信息 -- 按下"/"键打开搜索框,可在搜索框输入要搜索的内容

在配置界面下方有五个按钮,其功能如下:

-- < Select >:选中按钮,和enter按键功能相同 -- < Exit >:退出按钮,和esc按键功能相同 -- < Help >:帮助按钮,查看选中菜单的帮助信息 -- < Save >:保存按钮,保存修改后的配置文件 -- < Load >:加载按钮,加载指定的配置文件

下面以使能DNS命令为例,介绍如何通过图形化界面来配置uboot

进入"Command line interface"配置项 进入"Network commands"网络相关命令配置项 选中dns,按下"Y"键将其编译到uboot中 按两下esc键退出,如果有修改项目,在退出主界面时会提示是否需要保存保存后可在uboot源码中的".config"文件中发现多了"CONFIG_CMD_DNS=y"这一行 使用"make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16"命令编译uboot 注意:此时不能用脚本文件来编译,因为脚本文件在编译之前会清理工程,会删除掉.config文件,导致通过图形化界面配置的所有选项都被删除 编译完成烧写到SD卡后,重启开发板进入uboot命令模式,设置dns服务器的IP地址setenv dnsip 114.114.114.114 saveenv设置好后,使用dns命令即可查看百度官网的IP地址dns www.baidu.com2. menuconfig图形化配置原理2.1 make menuconfig过程分析

当输入make menuconfig以后会匹配到顶层Makefile中的如下代码:

%config: scripts_basic outputmakefile FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@ #其中build=-f ./scripts/Makefile.build obj ###将上面第二行的规则展开后: @make -f ./scripts/Makefile.build obj=scripts/kconfig menuconfig

Makefile.build会读取scripts/kconfig/Makefile中的内容,在 scripts/kconfig/Makefile中有如下代码:

menuconfig: $(obj)/mconf $config条目:是菜单里的具体配置项##########顶层Kconfig代码段########## menu "General setup" config LOCALVERSION string "Local version - append to U-Boot release" help ...... config LOCALVERSION_AUTO bool "Automatically append version information to the version string" default y #表示该配置项默认值是y,即默认被选中 help #表示帮助信息,告知配置项的含义,按下h或?会弹出help的内容 ...... config CC_OPTIMIZE_FOR_SIZE bool "Optimize for size" default y help ...... config SYS_MALLOC_F bool "Enable malloc() pool before relocation" default y if DM help ...... config SYS_MALLOC_F_LEN hex "Size of malloc() pool before relocation" depends on SYS_MALLOC_F default 0x400 help ...... menuconfig EXPERT bool "Configure standard U-Boot features (expert users)" default y help ...... if EXPERT config SYS_MALLOC_CLEAR_ON_INIT bool "Init with zeros the memory reserved for malloc (slow)" default y help ...... endif endmenu # General setup 以上代码可以看出,在menu/endmenu代码块中有大量的"config XXXXX"代码块(config条目)。假如使能了XXXXX功能,那么就会在.config文件中生成CONFIG_XXXXX 常用的三种变量类型:bool、tristate和string -- bool,有两种值,y和n -- tristate,有三种值,y、n和m -- string,用来存储本地字符串depends on和select########## arch/Kconfig代码段 ########## config SYS_GENERIC_BOARD bool depends on HAVE_GENERIC_BOARD #depends on依赖:依赖项选中后,被依赖项才能被选中 choice prompt "Architecture select" default SANDBOX config ARC bool "ARC architecture" select HAVE_PRIVATE_LIBGCC select HAVE_GENERIC_BOARD select SYS_GENERIC_BOARD select SUPPORT_OF_CONTROL #select方向依赖,“ARC”被选择后,四个select也会被选中choice/endchoice:定义一组可选择项,将多个类似配置项组合在一起,供用户单选或多选########## arch/Kconfig代码段 ########## choice prompt "Architecture select" default SANDBOX config ARC bool "ARC architecture" ...... config ARM bool "ARM architecture" ...... config AVR32 bool "AVR32 architecture" ...... config BLACKFIN bool "Blackfin architecture" ...... config M68K bool "M68000 architecture" ...... config MICROBLAZE bool "MicroBlaze architecture" ...... config MIPS bool "MIPS architecture" ...... config NDS32 bool "NDS32 architecture" ...... config NIOS2 bool "Nios II architecture" ...... config OPENRISC bool "OpenRISC architecture" config PPC bool "PowerPC architecture" ...... config SANDBOX bool "Sandbox" ...... config SH bool "SuperH architecture" select HAVE_PRIVATE_LIBGCC config SPARC bool "SPARC architecture" ...... config X86 bool "x86 architecture" ...... endchoicemenuconfig:和menu类似,但是menuconfig是带选项的菜单,其一般用法如下menuconfig MODULES #定义一个可选的菜单MODULES bool "菜单" if MODULES #只有选中了,if里面的内容才会显示 ...... endif # MODULES ##########顶层Kconfig代码段########## menu "General setup" ...... menuconfig EXPERT bool "Configure standard U-Boot features (expert users)" default y help ...... if EXPERT config SYS_MALLOC_CLEAR_ON_INIT bool "Init with zeros the memory reserved for malloc (slow)" default y help ...... endif endmenu # General setup 以上代码实现了一个带选项的菜单EXPERT,只有被选中了,if/endif里的内容才会显示出来 comment:用于在图形化界面中显示一行注释########## drviers/mtd/nand/Kconfig代码段########## config NAND_ARASAN bool "Configure Arasan Nand" help This enables Nand driver support for Arasan nand flash controller. This uses the hardware ECC for read and write operations. comment "Generic NAND options" #标注了一行注释3. 添加自定义菜单

图形化配置工具的主要工作就是在.config文件里生成前缀为“CONFIG_”变量,这些变量一般都有值(y/m/n),在uboot源码里会根据这些变量来决定编译哪个文件。下面介绍如何添加一个自已的自定义菜单,自定义菜单要求:

-- 在主界面中添加名为“My test menu”菜单项,菜单内部有一个配置项 -- 配置项为“MY_TESTCONFIG”,处于菜单“My test menu”中 -- 配置项的变量类型为bool,默认值为y -- 配置项菜单名字为“This is my test config” -- 配置项的帮助内容为“This is a empty config, just for testing!”完成以上菜单要求,只需要在顶层Kconfig文件末尾加上如下代码即可menu "My test menu" config MY_TESTCONFIG bool "This is my test config" default y help This is a empty config,just for test! endmenu #my test menu添加完成后,打开图形化配置界面 可见主菜单最后面出现零一个名为“My test menu”的子菜单,进入子菜单如下图示 按下help按键打开帮助文档,如下图示 打开.config文件,可以发现“CONFIG_MY_TESTCONFIG=y”,如下图示,至此在主菜单中添加自定义菜单的功能就实现了关注公众号“嵌入式攻城狮”,在公众号里发送“uboot”,即可获取uboot相关资料 !!!


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3